人性化 · Day.js 中文网 您所在的位置:网站首页 Dayjs 中文网 人性化 · Day.js 中文网

人性化 · Day.js 中文网

2024-05-20 04:30| 来源: 网络整理| 查看: 265

有时,你想要 dayjs#from 的所有优点,但又不想创建两个 Day.js 对象,你只想显示一段时间。

¥Sometimes, you want all the goodness of dayjs#from but you don't want to have to create two Day.js objects, you just want to display a length of time.

This requires the Duration plugin to work

This requires the RelativeTime plugin to work

dayjs.extend(duration) dayjs.extend(relativeTime) dayjs.duration(1, "minutes").humanize(); // a minute dayjs.duration(2, "minutes").humanize(); // 2 minutes dayjs.duration(24, "hours").humanize(); // a day

默认情况下,返回字符串是无后缀的。如果你想要后缀,请传入 true,如下所示。

¥By default, the return string is suffixless. If you want a suffix, pass in true as seen below.

dayjs.duration(1, "minutes").humanize(true); // in a minute

对于现在之前的后缀,传入一个负数。

¥For suffixes before now, pass in a negative number.

dayjs.duration(-1, "minutes").humanize(true); // a minute ago


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有